/* Copyright (c) 2004-2023 Peigen.info. All rights reserved. */
package info.peigen.hotpot.demo.service.socket;

import info.peigen.hotpot.component.gateway.core.util.HexUtil;
import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.extension.protocol.StringProtocol;
import org.smartboot.socket.transport.AioQuickClient;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;

/**
 * <b>(StringClient)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-08-09
 */
public class StringServer {
    public static void main(String[] args) throws IOException {
        MessageProcessor<String> processor   = (session, msg) -> System.out.println("receive from server: " + msg);
        AioQuickClient           client      = new AioQuickClient("36.155.18.177", 25998, new StringProtocol(), processor);
        AioSession               session     = client.start();
        WriteBuffer              writeBuffer = session.writeBuffer();
        byte[]                   data        = HexUtil.hexStringToByteArray("0103006000044417");
        writeBuffer.writeInt(data.length);
        writeBuffer.write(data);
        writeBuffer.flush();
    }
}
